package fr.smile.formation;

import java.io.File;
import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;

import fr.smile.sandbox.ProductDAO;

public class MyServlet extends HttpServlet {
	double i;
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		Resource res = new FileSystemResource(new File("/home/erlev/java/formation/workspace/Formation/WebContent/WEB-INF/spring/beansDescriptor.xml"));
		System.out.println(res.getURI());
		XmlBeanFactory factory = new XmlBeanFactory(res);

//		Product myProduct = (Product)factory.getBean("test");
//		req.setAttribute("test", myProduct);
//		
		ProductDAO myDao = (ProductDAO)factory.getBean("productDAO");
		
		req.setAttribute("test2", myDao.getProductByID(0));

		
		RequestDispatcher rd = getServletContext().getRequestDispatcher("/myservlet2");
		rd.forward(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		super.doPost(req, resp);
	}

}
